package com.ruoyi.web.controller.yf;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yf.domain.YfBucket;
import com.ruoyi.yf.service.IYfBucketService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 垃圾桶Controller
 *
 * @author XiaoYi...
 * @date 2020-03-17
 * 6af41598-5938-4af6-b107-cf1b48b7bbbb
 */
@Controller
@RequestMapping("/yf/bucket")
public class YfBucketController extends BaseController {
    private String prefix = "yf/bucket";

    @Autowired
    private IYfBucketService yfBucketService;

    @RequiresPermissions("yf:bucket:view")
    @GetMapping()
    public String bucket() {
        return prefix + "/bucket";
    }

    /**
     * 查询垃圾桶列表
     * fe1e9719-25c8-4983-bbf9-555855620fde
     */
    @RequiresPermissions("yf:bucket:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YfBucket yfBucket) {
        startPage();
        List<YfBucket> list = yfBucketService.selectYfBucketList(yfBucket);
        return getDataTable(list);
    }
    /**
     * XiaoYi...
     * 通过医院查询 垃圾桶列表
     *
     * @Date : 2020-03-18 14:29
     * 647a6cd0-422c-436e-9031-af7c617c2309
     */
    @RequiresPermissions("yf:bucket:list")
    @PostMapping("/adds/list")
    @ResponseBody
    @Log(title = "通过医院查询 垃圾桶列表")
    public TableDataInfo getBucketList(@RequestParam("hospitalId") Long hospitalId) {
        YfBucket yfBucket = new YfBucket();
        yfBucket.setHospitalId(hospitalId);
        List<YfBucket> list = yfBucketService.selectYfBucketList(yfBucket);
        return getDataTable(list);
    }




    /**
     * 导出垃圾桶列表
     * 05f29cc2-db52-40af-9c37-2b7e7572002c
     */
    @RequiresPermissions("yf:bucket:export")
    @Log(title = "垃圾桶", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YfBucket yfBucket) {
        List<YfBucket> list = yfBucketService.selectYfBucketList(yfBucket);
        ExcelUtil<YfBucket> util = new ExcelUtil<YfBucket>(YfBucket.class);
        return util.exportExcel(list, "bucket");
    }

    /**
     * 新增垃圾桶
     * 526c2c5b-4fbf-4908-b742-d6dc10751ea5
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 15e0eca6-8e0f-4781-a643-7349627019ac
     * 新增保存垃圾桶
     */
    @RequiresPermissions("yf:bucket:add")
    @Log(title = "垃圾桶", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YfBucket yfBucket) {
        return toAjax(yfBucketService.insertYfBucket(yfBucket));
    }

    /**
     * 修改垃圾桶
     * 1f9b7398-d291-4509-b948-6ee68ca16a4d
     */
    @GetMapping("/edit/{bucketId}")
    public String edit(@PathVariable("bucketId") Long bucketId, ModelMap mmap) {
        YfBucket yfBucket = yfBucketService.selectYfBucketById(bucketId);
        mmap.put("yfBucket", yfBucket);
        return prefix + "/edit";
    }

    /**
     * 修改保存垃圾桶
     * afec4bd9-1f46-4395-95a0-cad51040fdb3
     */
    @RequiresPermissions("yf:bucket:edit")
    @Log(title = "垃圾桶", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YfBucket yfBucket) {
        return toAjax(yfBucketService.updateYfBucket(yfBucket));
    }

    /**
     * 删除垃圾桶
     * 6d3a02cd-021d-418c-b695-2c0dde1bbb07
     */
    @RequiresPermissions("yf:bucket:remove")
    @Log(title = "垃圾桶", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(yfBucketService.deleteYfBucketByIds(ids));
    }
}
